package com.fxsh168.server.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.ListView;

import com.fxsh168.server.R;
import com.fxsh168.server.adapters.UserRecordAdapter;
import com.fxsh168.server.base.BaseActivity;
import com.fxsh168.server.entitys.UserTranslatinRecord;
import com.fxsh168.server.interfaces.Constant;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.List;

import okhttp3.Call;


public class TransactionRecordActivity extends BaseActivity {
    ListView mUserJiaoListView;
    UserRecordAdapter mUserRecoderAdapter;
    String ids;
    String mPhone, token;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transaction_record);
        //获取登录Sharepreferrnces里面的数据
        SharedPreferences sp = getSharedPreferences(Constant.LOGINCLASS, MODE_PRIVATE);
        mPhone = sp.getString("mPhone", "");
        token = sp.getString("token", "");
        mUserJiaoListView = (ListView) findViewById(R.id.mUserJiao);
        ids = getIntent().getStringExtra("ids");
        getTranlationRecod();
    }


    //交易记录
    public void getTranlationRecod() {
        OkHttpUtils.post().addParams("tid", 2 + "").addParams("aid", ids).url(Constant.TRANSLATIONRECORD)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                showToast("连接不上服务器");
            }

            @Override
            public void onResponse(String response, int id) {
                UserTranslatinRecord userTranslatinRecord = new Gson().fromJson(response, UserTranslatinRecord.class);
                List<UserTranslatinRecord.DataBean> data = userTranslatinRecord.getData();
                mUserRecoderAdapter = new UserRecordAdapter(data, TransactionRecordActivity.this);
                mUserJiaoListView.setAdapter(mUserRecoderAdapter);
                Log.e("tag", "司机交易记录" + response);
            }
        });
    }

}
